import React, { Component } from 'react';
import DomHelper from '../domHelper';
import LoaderHelper from './loaderHelper';

class GraphLoader extends Component {
    componentDidMount() {
        const { widget } = this.props;
        let geometry = new THREE.PlaneGeometry(widget.width, widget.height);
        let material = LoaderHelper.gradientMaterialCreator(widget);
        let mesh = LoaderHelper.meshCreator(null, THREE.PlaneGeometry, {}, widget, geometry, material);
        DomHelper.scene.add(mesh);
    }

    componentWillReceiveProps(nextProps) {
        if (nextProps.widget !== this.props.widget) {
            LoaderHelper.resetMeshItem(nextProps.widget, this.updateGraph);
        }
    }

    updateGraph(data) {
        let material = LoaderHelper.gradientMaterialCreator(data);
        DomHelper.selectedItem.material = material;
    }

    render() {
        return (<div />)
    }
}

export default GraphLoader;
